﻿using Microsoft.Extensions.DependencyInjection;
using PmSoft.Core;

namespace Demo.PetaPoco.Application.Services.Config;

/// <summary>
/// 应用程序配置服务类，继承自通用配置服务
/// </summary>
[Inject(ServiceLifetime.Scoped)]
public class AppConfigService : ConfigService<AppConfig>
{
	/// <summary>
	/// 构造函数，注入配置仓储
	/// </summary>
	/// <param name="repository">应用程序配置仓储</param>
	/// <exception cref="ArgumentNullException">当仓储参数为 null 时抛出</exception>
	public AppConfigService(ConfigRepository repository)
		: base(repository)
	{
	}

	/// <summary>
	/// 初始化应用程序配置的实现
	/// </summary>
	/// <param name="config">待初始化的配置对象</param>
	/// <returns>已完成的任务</returns>
	/// <exception cref="ArgumentNullException">当配置对象为 null 时抛出</exception>
	protected override Task InitializeAsync(AppConfig config)
	{
		// 设置默认配置值
		config.AppName = "Demo";
		config.MaxConnections = 100;
		config.IsEnabled = true;

		return Task.CompletedTask;
	}

}